package minidb.parse.exps;
import java.util.*;
import minidb.parse.exps.SelectExp.JoinType;;

public class TableList
{
	public List<Table> tableList;
	public JoinType jType;
	public JoinCondition joinCondition;
	
	
	public TableList()
	{
		this.tableList = new ArrayList<Table>();
		this.jType=null;
		this.joinCondition=null;
	}

	public TableList AddTable(Table t)
	{
		this.tableList.add(t);
		return this;
	}
	
	public List<Table> GetTableList()
	{
		return this.tableList;
	}
	
	public TableList SetJType(JoinType jt)
	{
		this.jType=jt;
		return this;
	}
	
	public TableList SetJCondition(JoinCondition jc)
	{
		this.joinCondition=jc;
		return this;
	}
	
	public String Print()
	{
		StringBuilder sb=new StringBuilder("");
		
		if(this.jType==null)
		{
			for(int i=0;i<this.tableList.size();i++)
			{
				sb.append(this.tableList.get(i).Print());
				if(i!=this.tableList.size()-1)
					sb.append(",");
			}
		}
		else
		{
			sb.append(this.tableList.get(0).Print());
			switch(this.jType)
			{
				case INNER:
					sb.append(" INNER JOIN ");
					break;
				case NATURAL:
					sb.append(" NATURAL JOIN ");
					break;
				case LEFT:
					sb.append(" LEFT OUTER JOIN ");
					break;
				case RIGHT:
					sb.append(" RIGHT OUTER JOIN ");
					break;
				case FULL:
					sb.append(" FULL OUTER JOIN ");
					break;
			}
			sb.append(this.tableList.get(1).Print());
			
			sb.append(this.joinCondition.Print());

		}
		
		return sb.toString();
	}
}







